/**
 * $Id: ImageShape.java,v 1.6 2011-01-05 11:20:51 gaudenz Exp $
 * Copyright (c) 2007-2010, Gaudenz Alder, David Benson
 */
package com.kg.rails.component.editor.shape;

import com.kg.rails.component.editor.canvas.Graphics2DCanvas;
import com.kg.rails.component.editor.util.Constants;
import com.kg.rails.component.editor.util.EditorUtils;
import com.kg.rails.component.editor.view.CellState;

import java.awt.*;

/**
 * A rectangular shape that contains a single image
 */
public class ImageShape extends RectangleShape {

    /**
     *
     */
    public void paintShape(Graphics2DCanvas canvas, CellState state) {
        super.paintShape(canvas, state);

        boolean flipH = EditorUtils.isTrue(state.getStyle(),
                Constants.STYLE_IMAGE_FLIPH, false);
        boolean flipV = EditorUtils.isTrue(state.getStyle(),
                Constants.STYLE_IMAGE_FLIPV, false);

        canvas.drawImage(getImageBounds(canvas, state),
                getImageForStyle(canvas, state),
                Graphics2DCanvas.PRESERVE_IMAGE_ASPECT, flipH, flipV);
    }

    /**
     *
     */
    public Rectangle getImageBounds(Graphics2DCanvas canvas, CellState state) {
        return state.getRectangle();
    }

    /**
     *
     */
    public boolean hasGradient(Graphics2DCanvas canvas, CellState state) {
        return false;
    }

    /**
     *
     */
    public String getImageForStyle(Graphics2DCanvas canvas, CellState state) {
        return canvas.getImageForStyle(state.getStyle());
    }

    /**
     *
     */
    public Color getFillColor(Graphics2DCanvas canvas, CellState state) {
        return EditorUtils.getColor(state.getStyle(),
                Constants.STYLE_IMAGE_BACKGROUND);
    }

    /**
     *
     */
    public Color getStrokeColor(Graphics2DCanvas canvas, CellState state) {
        return EditorUtils.getColor(state.getStyle(),
                Constants.STYLE_IMAGE_BORDER);
    }

}
